<template>
    <div class="">
        <!-- 头部导航栏 -->
        <div class="head">
            <h3>食谱秀网</h3>
            <svg class="icon icon-caidan" aria-hidden="true" @click="show = !show">
                <use xlink:href="#icon-caidan"></use>
            </svg>
            <!-- 头部隐藏栏 -->
            <transition name="fade">
                <ul class="tab" v-if="!show">
                    <router-link to="/index">
                        <li>
                            <span>
                                <svg class="icon" aria-hidden="true">
                                    <use xlink:href="#icon-icons_statistics"></use>
                                </svg>
                                首页
                            </span>
                        </li>
                    </router-link>
                    <router-link to="/classify">
                        <li>
                            <span>
                                <svg class="icon" aria-hidden="true">
                                    <use xlink:href="#icon-tag"></use>
                                </svg>
                                食材分类
                            </span>
                        </li>
                    </router-link>
                    <router-link to="/Cookbook">
                        <li>
                            <span>
                                <svg class="icon" aria-hidden="true">
                                    <use xlink:href="#icon-tag"></use>
                                </svg>
                                菜谱大全
                            </span>
                        </li>
                    </router-link>
                    <router-link to="/HomeCooked">
                        <li>
                            <span>
                                <svg class="icon" aria-hidden="true">
                                    <use xlink:href="#icon-tag"></use>
                                </svg>
                                家常菜谱
                            </span>
                        </li>
                    </router-link>
                    <router-link to="/restriction">
                        <li>
                            <span>
                                <svg class="icon" aria-hidden="true">
                                    <use xlink:href="#icon-star"></use>
                                </svg>
                                食物相克
                            </span>
                        </li>
                    </router-link>
                    <router-link to="/PregnantDiet">
                        <li>
                            <span>
                                <svg class="icon" aria-hidden="true">
                                    <use xlink:href="#icon-tag"></use>
                                </svg>
                                孕妇食谱
                            </span>
                        </li>
                    </router-link>
                    <router-link to="/FoodInformation">
                        <li>
                            <span>
                                <svg class="icon" aria-hidden="true">
                                    <use xlink:href="#icon-tag"></use>
                                </svg>
                                美食资讯
                            </span>
                        </li>
                    </router-link>
                </ul>
            </transition>
            <!-- 侧边栏 -->
            <div class="aside">
                <div class="phone">
                    <router-link  to="/appdownloads">
                        <img src="../../assets/images/QR code/float-icon3.png" alt="">
                    </router-link>
                </div>
                <div class="up" @click="backTop" v-show="backTopShow">
                    <img src="../../assets/images/QR code/float-icon1.png" alt="">
                </div>
            </div>
        </div>
        <!-- 搜索 -->
        <div class="sousuo">
            <svg class="icon icon-fangdajing" aria-hidden="true">
                <use xlink:href="#icon-fangdajing1"></use>
            </svg>
            <input type="text" class="sousuo1" placeholder="红烧肉">
            <router-link to="/search">
                <input type="submit"  class="sousuo2" value="搜索">
            </router-link>
            <p>位置： 首页 > 家常菜 > 红烧肉的做法大全</p>
        </div>
        <!-- 开头 -->
        <div class="top">
            <img src="../../assets/images/details/20170831143704_54697.jpg" alt="">
            <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;红烧肉的做法大全</p>
            <span>
                &nbsp;&nbsp;&nbsp;&nbsp;红烧肉是热菜菜谱之一，以五花肉为制作主料，红烧肉的烹饪技巧以砂锅为主，口味属于甜味。
                红烧肉是一道著名的本帮菜，充分体现了本帮菜“浓油赤酱”的特点。
                【适宜】气虚质、气郁质、阳虚质、平和质
                【禁忌】湿热质、痰湿质、血瘀质
            </span>
        </div>
        <!-- 主体部分 -->
        <ul class="foods">
            <li v-for="(item,index) in details" :key="index">
                <router-link to="/index">
                    <img :src="item.src" alt="">
                    <p>{{item.name}}</p>
                </router-link>
            </li>
        </ul>
        <!-- 按钮切换 -->
        <div class="change">
            <button>首页</button>
            <button>上一页</button>
            <button>下一页</button>
            <button>尾页</button>
        </div>
        <!-- 推荐部分 -->
        <div class="recommend">
            <li v-for="(item,index) in recommend" :key="index">
                <router-link to="/index">
                    <img :src="item.src" alt="">
                    <p>{{item.explanation}}</p>
                </router-link>
            </li>
        </div>
        <!-- 相关搜索 -->
        <h3 class="titles">相关搜索</h3>
        <ul class="find">
            <li v-for="(item,index) in find" :key="index">
                <router-link to="/dishes">
                    <p>{{item}}</p>
                </router-link>
            </li>
        </ul>
        <!-- 菜谱热搜榜 -->
        <h3 class="title">菜谱热搜榜</h3>
        <ul class="food">
            <li v-for="(item,index) in search.slice(0,48)" :key="index">
                <router-link to="/dishes">
                    <p>{{item}}</p>
                </router-link>
            </li>
        </ul>
        <!-- 底部  -->
        <div class="foot">
            Copyright 食谱秀 m.shipuxiu.com <br>
            <p> 
                官方微信号: <span style="color: #ff0000;">chaoliu1588 </span> 
                <router-link to="https://m.shipuxiu.com/fenlei/">食谱分类</router-link>
                <router-link to="https://support.qq.com/products/113359/">我要吐槽</router-link>
                <router-link to="https://new.cnzz.com/v1/login.php?siteid=5433565">站长统计 </router-link>
             </p> 
        </div>

    </div>
    
</template>
<script>
export default {
    data(){
        return{
            show:true,
            details:[],
            recommend:[],
            find:[],
            search:[],
            backTopShow:false
        }
    },
    mounted(){
        // 获取数据
        this.$http.get('../../data/data.json')
        .then((response)=> {
            this.details = response.data.details
            this.recommend = response.data.recommend
            this.find = response.data.find
            this.search = response.data.search
        })
        .catch(function (error) {
            console.log(error);
        })
        .then(function () {
            // always executed
        });
        window.addEventListener('scroll', this.handleScroll)
    },
    methods: {
         backTop(){
            let back = setInterval(() =>{
                 if(document.body.scrollTop||document.documentElement.scrollTop){
                    document.body.scrollTop -= 100;
                    document.documentElement.scrollTop -= 100;
                }else{
                    clearInterval(back)
                }
            });
        },
        handleScroll(){
             if (document.documentElement.scrollTop + document.body.scrollTop > 100) {
                 this.backTopShow = true;
            }else{
                 this.backTopShow = false;
            }
        }
    }
}
</script>

<style scoped>
    .sousuo{
        height: 10vh;
    }
    .foot{
        height: 7vh;
        margin-top: 30px;
    }
    /* 顶部 */
    .top{
        width: 100%;
        height: 12vh;
        font-size: 12px;
    }
    .top img{
        width: 26%;
        height: 12vh;
        float: left;
    }
    .top p{
        color: #333333;
        font-weight: 800;
    }
    .top span{
        display: block;
        line-height: 3vh;
        padding: 5px 10px 0px 10px;
        display: -webkit-box;
        text-overflow: ellipsis;
        overflow : hidden;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        color: #4c4c4c;
    }
    /* 主体部分 */
    .foods{
        margin-top: 20px;
        width: 100%;
        height: 188vh;
    }
    .foods li{
        width: 45%;
        height: 5vh;
        margin-top: 10px;
    }
    .foods li img{
        width: 82%;
        height: 14vh;
        margin-left: 20px;
    }
    .foods li p{
        font-size: 14px;
        text-align: center;
        color: #333333;
    }
    .recommend{
        margin-top: -60px;
        background: #f5f5f5;
    }
    /* 相关搜索 */
    .find{
        width: 100%;
        height: 20vh;
        border-top: 1px solid #f2f2f2;
        border-bottom: 4px solid #f2f2f2;
        font-size: 13px;
    }
    .find li{
        width: 45%;
        line-height: 4vh;
    }
    .find li a{
        color: #4c4c4c;
        text-decoration: none;
    }
    .titles{
        color: #f67622;
        margin-left: 10px;
        font-size: 18px;
        margin-bottom: 5px;
    }
    .food{
        margin-top: 10px;
        width: 100%;
        height: 133vh;
        border-bottom: 1px solid #f4f4f4;
    }
    .food li{
        width: 28%;
        height: 6.5vh;
        background: #f4f4f4;
        border-radius: 4px;
        margin-bottom: 15px;
    }
    .food li p{
        font-size: 14px;
        text-align: center;
        color: #333333;
        line-height: 6.5vh;
        
    }
    .title{
        color: #098bd6;
        margin-left: 20px;
        font-size: 18px;
        margin-top: 30px;
    }
</style>